﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MapAndCharacter_Filip
{
    public partial class HostControls : Form
    {
        Dictionary<string, int> stringToID;

        public HostControls()
        {
            InitializeComponent();
            stringToID = new Dictionary<string, int>();
            int monCount = 1;
            int charCount = 1;
            foreach(KeyValuePair<int, MovableSprite> entry in GameState.game.characters){
                if (entry.Key >= 100)
                {
                    string monster = "Monster " + monCount;
                    stringToID.Add(monster, entry.Key);
                    comboBox1.Items.Add(monster);
                    monCount++;
                }
                else
                {
                    string character = "Character " + charCount;
                    stringToID.Add(character, entry.Key);
                    comboBox1.Items.Add(character);
                    charCount++;
                }
            }
            comboBox1.Click += new EventHandler(OnBox1Click);
            
        }

        private void OnBox1Click(object sender, EventArgs e)
        {
            this.comboBox1.Items.Clear();
            stringToID.Clear();
            int monCount = 1;
            int charCount = 1;
            foreach (KeyValuePair<int, MovableSprite> entry in GameState.game.characters)
                if (entry.Key >= 100)
                {
                    string monster = "Monster " + monCount;
                    stringToID.Add(monster, entry.Key);
                    comboBox1.Items.Add(monster);
                    monCount++;
                }
                else
                {
                    string character = "Character " + charCount;
                    stringToID.Add(character, entry.Key);
                    comboBox1.Items.Add(character);
                    charCount++;
                }
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            //if (comboBox1.Text.Substring(0, 1).Equals("M"))
            //{
                GameState.hostChar = stringToID[comboBox1.Text];
                Console.WriteLine("Set controlled char to : " + GameState.hostChar);
                //Int32.Parse(comboBox1.Text.Substring(8, comboBox1.Text.Length -8)) + 99;
            //}
            //else
            //{
               // GameState.hostChar = Int32.Parse(comboBox1.Text.Substring(10, comboBox1.Text.Length - 10));
            //}
            
        }
    }
}
